#include "bluetooth_connect.hpp"

#include "BluetoothSerial.h"  // 引入经典蓝牙库

namespace bluetooth_connect
{

BluetoothSerial SerialBT;  // 创建蓝牙串口对象

void setupBluetooth()
{
    if (!SerialBT.begin("ESP32_BT")) {
        Serial.println("Bluetooth initialization failed!");
    } else {
        Serial.println("Bluetooth is ready to pair");
    }
}

void loopBluetooth()
{
    // 检查是否有来自手机的数据
    if (SerialBT.available()) {
        String received = SerialBT.readString();  // 读取手机发送的数据
        Serial.println("Received: " + received);  // 打印接收到的数据

        // 回复消息
        SerialBT.println("Message received: " + received);
    }
}

}  // namespace bluetooth_connect